package com.jubaozan.framework.sentinel.springmvc.listener;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.csp.sentinel.cluster.flow.rule.ClusterFlowRuleManager;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.csp.sentinel.util.AppNameUtil;
import com.jubaozan.framework.sentinel.constant.RuleKeyConstant;
import com.jubaozan.framework.sentinel.listener.AbstractRulePropertyListener;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author jiangjinwu
 * @version 1.0
 * @since 2025/7/15 10:37
 */

@Slf4j
@Component
public class AuthorityRulePropertyListener extends AbstractRulePropertyListener<AuthorityRule> {

    @Autowired
    RuleKeyConstant ruleKeyConstant;

    public AuthorityRulePropertyListener() {
        super(AuthorityRule.class);
    }

    @Override
    protected void doLoad(List<AuthorityRule> conf) {
        AuthorityRuleManager.loadRules(conf);
        log.info("接收到授权规则加载: {}", conf);
    }


    @Override
    protected String getRedisKey() {
        return ruleKeyConstant.getAuthorityRuleKey();
    }

}
